added format.bytes_per_pixel s/bands/components/
authorØyvind Kolås <ok@src.gnome.org>
Fri, 26 Aug 2005 13:44:02 +0000 (13:44 +0000)
committerØyvind Kolås <ok@src.gnome.org>
Fri, 26 Aug 2005 13:44:02 +0000 (13:44 +0000)
ChangeLog
babl/babl-classes.h
babl/babl-format.c
babl/babl-image.c
babl/babl-pixel-format.c

index 22cf7dc9124c0aee04e4078c636b237a3728f7fd..38557b714467652835cf4eda6241f70bcf19cb95 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2005-08-25  Øyvind Kolås  <pippin@gimp.org>
+
+       * babl/babl-classes.h:
+               BablFormat: added .bytes_per_pixel
+               BablImage: s/bands/components/
+       * babl/babl-conversion.c: s/bands/components/
+       * babl/babl-image.c: s/bands/components/
+       * babl/babl-pixel-format.c: (format_new) check if provided pixel
+       format matches model. Calculate .bytes_per_pixel.
+
 2005-08-25  Øyvind Kolås  <pippin@gimp.org>
 
        * babl/babl-classes.h:
index 5e11c8b74ef164b04edc22dcbb6457b51cdce93a..38119345fa7fa7c7f00542dfec49b50224610bb5 100644 (file)
@@ -201,6 +201,7 @@ typedef struct
   BablType       **type;
   BablSampling   **sampling;
   BablModel       *model;
+  int              bytes_per_pixel;
   int              planar;
 } BablFormat;
 
@@ -209,7 +210,7 @@ typedef struct
   BablInstance    instance;
   BablFormat     *format;    /*< (if known) */
   BablModel      *model;     /*< (always known) */
-  int             bands;
+  int             components;
   BablComponent **component;
   BablSampling  **sampling;
   BablType      **type;
index fa0a9b4650e46172fb2637bb638a2b341e7a04a4..fe3406d1746edc566c094e86edb1dd884325bf22 100644 (file)
@@ -49,6 +49,27 @@ format_new (const char     *name,
 {
   Babl *babl;
 
+  {
+    int i;
+    /* i is desintation position */
+    for (i=0 ; i<model->components; i++)
+      {
+        int j;
+
+        for (j=0;j<components;j++)
+          {
+            if (component[j] == model->component[i])
+              goto component_found;
+          }
+        babl_log ("%s(): matching source component for %s in model %s not found",
+           __FUNCTION__, 
+           model->component[i]->instance.name, model->instance.name);
+        exit (-1);
+        component_found:
+        ;
+      }
+  }
+
   /* allocate all memory in one chunk */
   babl  = babl_malloc (sizeof (BablFormat) +
                        strlen (name) + 1 +
@@ -58,25 +79,33 @@ format_new (const char     *name,
                        sizeof (int)            * (components) +
                        sizeof (int)            * (components));
 
+  babl->format.from      = NULL;
+  babl->format.to        = NULL;
   babl->format.component = ((void *)babl) + sizeof (BablFormat);
   babl->format.type      = ((void *)babl->format.component) + sizeof (BablComponent*) * (components);
   babl->format.sampling  = ((void *)babl->format.type)      + sizeof (BablType*) * (components);
-  babl->instance.name          = ((void *)babl->format.sampling)  + sizeof (BablSampling*) * (components);
+  babl->instance.name    = ((void *)babl->format.sampling)  + sizeof (BablSampling*) * (components);
   
   babl->class_type    = BABL_FORMAT;
   babl->instance.id   = id;
 
   strcpy (babl->instance.name, name);
+
   babl->format.model      = model;
   babl->format.components = components;
-  babl->format.planar     = planar;
 
   memcpy (babl->format.component, component, sizeof (BablComponent*) * components);
   memcpy (babl->format.type     , type     , sizeof (BablType*)      * components);
   memcpy (babl->format.sampling , sampling , sizeof (BablSampling*)  * components);
 
-  babl->format.from = NULL;
-  babl->format.to   = NULL;
+  babl->format.planar     = planar;
+
+  babl->format.bytes_per_pixel = 0;
+  {
+    int i;
+    for (i=0;i<components;i++)
+      babl->format.bytes_per_pixel += type[i]->bits/8;
+  }
 
   return babl;
 }
index 1e36d960fab367d9815a20113cc0d5cafc310caf..7e02aabc3b62050f78dd22cf5bb5e876e996d3b9 100644 (file)
@@ -31,7 +31,7 @@
 static Babl *
 image_new (BablFormat     *format,
            BablModel      *model,
-           int             bands,
+           int             components,
            BablComponent **component,
            BablSampling  **sampling,
            BablType      **type,
@@ -43,31 +43,31 @@ image_new (BablFormat     *format,
 
   /* allocate all memory in one chunk */
   babl  = babl_malloc (sizeof (BablImage) +
-                       sizeof (BablComponent*) * (bands) +
-                       sizeof (BablSampling*)  * (bands) +
-                       sizeof (BablType*)      * (bands) +
-                       sizeof (void*)          * (bands) +
-                       sizeof (int)            * (bands) +
-                       sizeof (int)            * (bands));
+                       sizeof (BablComponent*) * (components) +
+                       sizeof (BablSampling*)  * (components) +
+                       sizeof (BablType*)      * (components) +
+                       sizeof (void*)          * (components) +
+                       sizeof (int)            * (components) +
+                       sizeof (int)            * (components));
   babl->image.component     = ((void *)babl)                  + sizeof (BablImage);
-  babl->image.sampling      = ((void *)babl->image.component) + sizeof (BablComponent*) * (bands);
-  babl->image.type          = ((void *)babl->image.sampling)  + sizeof (BablSampling*)  * (bands);
-  babl->image.data          = ((void *)babl->image.type)      + sizeof (BablType*)      * (bands);
-  babl->image.pitch         = ((void *)babl->image.data)      + sizeof (void*)          * (bands);
-  babl->image.stride        = ((void *)babl->image.pitch)     + sizeof (int)            * (bands);
-
-  babl->class_type    = BABL_IMAGE;
-  babl->instance.id   = 0;
-  babl->instance.name = "slaritbartfast";
-
-  babl->image.format        = format;
-  babl->image.model         = model;
-  babl->image.bands         = bands;
-  memcpy (babl->image.component, component, bands * sizeof(void*));
-  memcpy (babl->image.type,      type,      bands * sizeof(void*));
-  memcpy (babl->image.data,      data,      bands * sizeof(void*));
-  memcpy (babl->image.pitch,     pitch,     bands * sizeof(int));
-  memcpy (babl->image.stride,    stride,    bands * sizeof(int));
+  babl->image.sampling      = ((void *)babl->image.component) + sizeof (BablComponent*) * (components);
+  babl->image.type          = ((void *)babl->image.sampling)  + sizeof (BablSampling*)  * (components);
+  babl->image.data          = ((void *)babl->image.type)      + sizeof (BablType*)      * (components);
+  babl->image.pitch         = ((void *)babl->image.data)      + sizeof (void*)          * (components);
+  babl->image.stride        = ((void *)babl->image.pitch)     + sizeof (int)            * (components);
+
+  babl->class_type       = BABL_IMAGE;
+  babl->instance.id      = 0;
+  babl->instance.name    = "slaritbartfast";
+  babl->image.format     = format;
+  babl->image.model      = model;
+  babl->image.components = components;
+
+  memcpy (babl->image.component, component, components * sizeof(void*));
+  memcpy (babl->image.type,      type,      components * sizeof(void*));
+  memcpy (babl->image.data,      data,      components * sizeof(void*));
+  memcpy (babl->image.pitch,     pitch,     components * sizeof(int));
+  memcpy (babl->image.stride,    stride,    components * sizeof(int));
 
   return babl;
 }
@@ -152,7 +152,7 @@ babl_image (void *first,
 {
   va_list        varg;
   Babl          *babl;
-  int            components     = 0;
+  int            components= 0;
   BablFormat    *format    = NULL;
   BablModel     *model     = NULL;
   BablComponent *component [BABL_MAX_COMPONENTS];
index fa0a9b4650e46172fb2637bb638a2b341e7a04a4..fe3406d1746edc566c094e86edb1dd884325bf22 100644 (file)
@@ -49,6 +49,27 @@ format_new (const char     *name,
 {
   Babl *babl;
 
+  {
+    int i;
+    /* i is desintation position */
+    for (i=0 ; i<model->components; i++)
+      {
+        int j;
+
+        for (j=0;j<components;j++)
+          {
+            if (component[j] == model->component[i])
+              goto component_found;
+          }
+        babl_log ("%s(): matching source component for %s in model %s not found",
+           __FUNCTION__, 
+           model->component[i]->instance.name, model->instance.name);
+        exit (-1);
+        component_found:
+        ;
+      }
+  }
+
   /* allocate all memory in one chunk */
   babl  = babl_malloc (sizeof (BablFormat) +
                        strlen (name) + 1 +
@@ -58,25 +79,33 @@ format_new (const char     *name,
                        sizeof (int)            * (components) +
                        sizeof (int)            * (components));
 
+  babl->format.from      = NULL;
+  babl->format.to        = NULL;
   babl->format.component = ((void *)babl) + sizeof (BablFormat);
   babl->format.type      = ((void *)babl->format.component) + sizeof (BablComponent*) * (components);
   babl->format.sampling  = ((void *)babl->format.type)      + sizeof (BablType*) * (components);
-  babl->instance.name          = ((void *)babl->format.sampling)  + sizeof (BablSampling*) * (components);
+  babl->instance.name    = ((void *)babl->format.sampling)  + sizeof (BablSampling*) * (components);
   
   babl->class_type    = BABL_FORMAT;
   babl->instance.id   = id;
 
   strcpy (babl->instance.name, name);
+
   babl->format.model      = model;
   babl->format.components = components;
-  babl->format.planar     = planar;
 
   memcpy (babl->format.component, component, sizeof (BablComponent*) * components);
   memcpy (babl->format.type     , type     , sizeof (BablType*)      * components);
   memcpy (babl->format.sampling , sampling , sizeof (BablSampling*)  * components);
 
-  babl->format.from = NULL;
-  babl->format.to   = NULL;
+  babl->format.planar     = planar;
+
+  babl->format.bytes_per_pixel = 0;
+  {
+    int i;
+    for (i=0;i<components;i++)
+      babl->format.bytes_per_pixel += type[i]->bits/8;
+  }
 
   return babl;
 }